package datastructure.tree;

/**
 *
 * @author Lei
 */
public class IsBinaryTreeIdentical {

    public static boolean isBinaryTreeIdentical(TreeNode root1, TreeNode root2) {
        if (root1 == null && root2 == null) {
            return true;
        }

        if (root1 == null || root2 == null) {
            return false;
        }

        if (root1.value != root2.value) {
            return false;
        }

        return (isBinaryTreeIdentical(root1.left, root2.left)
                && isBinaryTreeIdentical(root1.right, root2.right));
    }
}
